package design.action.观察者;

import java.util.Observable;
import java.util.Observer;

/**
 * 注册 被观察者
 */
public class MyObservable extends Observable {
    /**
     * sprig 注入
     */
    private final static MyObservable observable = new MyObservable();
    private final static Observer myObserver1 = new Observer1();
    private final static Observer myObserver2 = new Observer2();

    static {
        observable.addObserver(myObserver1);
        observable.addObserver(myObserver2);
    }

    public void run() {
        setChanged();
        //只有在setChange()被调用后，notifyObservers()才会去调用update()，否则什么都不干。
        notifyObservers("参数");
    }

    public static void main(String[] args) {
        observable.run();
    }
}
